<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
		<style>
			.service_goods {
				display: none;
			}

			.choose_shopname {
				line-height: 40px;
			}
		</style>
	</head>
	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" wid100 lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item"  style="display: none;">
								<label class="layui-form-label">商品状态1</label>
								<input type="text" name="status" value="">
							</div>
							<div class="layui-form-item" style="display: none;">
								<label class="layui-form-label">商品类型</label>
								<input type="text" name="goods_type" value="0" class="layui-input" lay-verify="goods_type">
								<!-- <div class="layui-input-block goods_type"></div> -->
							</div>
							<div class="layui-form-item"  style="display: none;">
								<label class="layui-form-label">客户端</label>
								<!-- <input type="text" name="client" value="200,201,202" class="layui-input" lay-verify="client"> -->
								<!-- <div class="layui-input-block icon_type"></div> -->
							</div>
							<div class="layui-form-item"  style="display: none;">
								<label class="layui-form-label">分期</label>
								<div class="layui-input-block fq_status"></div>
							</div>

							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">频道</label>
									<div class="layui-input-inline">
										<select lay-search="" lay-filter="channelid" lay-verify="" name="channelid"
											class="site_icon_group" id="channelid"></select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label" style="width: 180px;">
										<!-- <button type="button" class="layui-btn layui-btn-sm"
											onclick="chooseShop()">选择店铺</button> -->
										&nbsp;&nbsp;店铺：
									</label>
									<div class="layui-input-inline">
										<div class="choose_shopname" id="choose_shopname">店铺未选择</div>
										<input type="hidden" id="sub_shopid" name="sub_shopid" class="layui-input"
											lay-verify="sub_shopid">
										<input type="hidden" id="sub_shopname" name="sub_shopname" class="sub_shopname"
											lay-verify="sub_shopname">
									</div>
								</div>
								<div class="layui-inline"  style="display: none;">
									<label class="layui-form-label">是否推荐</label>
									<div class="layui-input-inline">
										<input type="radio" name="is_recommend" value="1" title="是">
										<div class="layui-unselect layui-form-radio layui-form-radioed"><i
												class="layui-anim layui-icon"></i>
											<div>是</div>
										</div><input type="radio" name="is_recommend" value="0" title="否"
											checked="checked">
										<div class="layui-unselect layui-form-radio"><i
												class="layui-anim layui-icon"></i>
											<div>否</div>
										</div>
									</div>
								</div>
								<div class="layui-inline"  style="display: none;">
									<label class="layui-form-label">能否加入购物车</label>
									<div class="layui-input-inline">
										<input type="radio" name="cart" value="1" title="是" checked="checked">
										<div class="layui-unselect layui-form-radio layui-form-radioed"><i
												class="layui-anim layui-icon"></i>
											<div>是</div>
										</div><input type="radio" name="cart" value="0" title="否">
										<div class="layui-unselect layui-form-radio"><i
												class="layui-anim layui-icon"></i>
											<div>否</div>
										</div>
									</div>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">商品名称<span style="color:red">*</span></label>
								<div class="layui-input-block">
									<input type="text" name="skuname" placeholder="请输入商品名称" autocomplete="off"
										class="layui-input" lay-verify="required">
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-block">
									<label class="layui-form-label">商品简称<span style="color:red">*</span></label>
									<div class="layui-input-block">
										<input type="text" name="title" placeholder="请输入商品简称" autocomplete="off"
											class="layui-input" lay-verify="required">
									</div>
								</div>
							</div>
							
							<!--<div class="layui-form-item">
								<label class="layui-form-label">产品编号</label>
								<div class="layui-input-inline">
									<input type="text" name="spuid" placeholder="请输入产品编号" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid layui-word-aux"><a href="Javascript:;" onclick="searchdata('spuid')">选择</a></div>
							</div> -->


							<div class="layui-form-item service_goods">
								<label class="layui-form-label">选择子商品:</label>

								<!--<div class="layui-input-block">
									<textarea type="text" name="sub_skuname" placeholder="请输入选择子商品" autocomplete="off" class="layui-textarea sub_skuname"></textarea>
									<input type="text" name="sub_skuid" placeholder="请输入选择子商品" autocomplete="off" class="layui-input sub_skuid" style="display: none;">
								</div>-->
								<div class="layui-input-block">
									<div class="layui-form">
										<table class="layui-table">
											<colgroup>
												<col width="150">
												<col width="150">
												<col width="150">
											</colgroup>
											<thead>
												<tr>
													<th>商品名称</th>
													<th>商品编号</th>
													<th>操作</th>
												</tr>
											</thead>
											<tbody class="tbody_tr" id="tbody_tr"></tbody>
										</table>
									</div>
								</div>
								<div class="layui-input-block">
									<div class="layui-form-mid layui-word-aux">
										<a href="Javascript:;" onclick="searchdata('sub_skuid')">选择</a>
									</div>
								</div>
							</div>

							<div class="layui-form-item service_goods">
								<div class="layui-inline">
									<label class="layui-form-label">开始服务时间</label>
									<div class="layui-input-inline">
										<input type="text" name="rangeStartTime" class="layui-input" id="rangeStartTime"
											placeholder=" HH:mm:ss">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">结束服务时间</label>
									<div class="layui-input-inline">
										<input type="text" name="rangeEndTime" class="layui-input" id="rangeEndTime"
											placeholder=" HH:mm:ss">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">服务时长(分钟)</label>
									<div class="layui-input-inline">
										<input type="text" name="intervalTime" class="layui-input" />
									</div>
								</div>
							</div>




							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">分类<span style="color:red">*</span></label>
									<div class="layui-input-inline">
										<input type="text" name="categoryname" lay-verify="required" placeholder="请选择分类"
											autocomplete="off" class="layui-input cat_name" readonly>
										<input type="hidden" id="catid" name="catid" lay-verify="" placeholder="请选择分类"
											autocomplete="off" class="layui-input cat_id">
									</div>
									<div class="layui-form-mid layui-word-aux">
										<a href="Javascript:;" onclick="searchdata('catid')">选择</a>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">产品名称</label>
									<div class="layui-input-inline">
										<input type="text" name="spuname" placeholder="请输入产品名称" autocomplete="off"
											class="layui-input" lay-verify="" readonly>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">产品编号</label>
									<div class="layui-input-inline">
										<input type="text" name="spuid" placeholder="请输入产品编号" autocomplete="off"
											class="layui-input" readonly>
									</div>
									<div class="layui-form-mid layui-word-aux"><a href="Javascript:;"
											onclick="searchdata('spuid')">选择</a></div>
								</div>
							</div>
							<div class="layui-form-item" style="display: none;">
								<div class="layui-inline">
									<label class="layui-form-label">直推佣金</label>
									<div class="layui-input-block">
										<input type="text" name="direct_fee" placeholder="请输入直推佣金" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">间推佣金</label>
									<div class="layui-input-block">
										<input type="text" name="indirect_fee" placeholder="请输入间推佣金" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">团长佣金</label>
									<div class="layui-input-block">
										<input type="text" name="leader_fee" placeholder="请输入团长佣金" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">管理奖</label>
									<div class="layui-input-block">
										<input type="text" name="team_fee" placeholder="请输入管理奖" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">合伙人佣金</label>
									<div class="layui-input-block">
										<input type="text" name="copartner_fee" placeholder="请输入合伙人佣金"
											autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">服务站佣金</label>
									<div class="layui-input-block">
										<input type="text" name="station_fee" placeholder="请输入服务站佣金" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item service_goods">
								<div class="layui-inline">
									<label class="layui-form-label">区域店铺佣金</label>
									<div class="layui-input-inline">
										<input type="text" name="area_fee" placeholder="请输入区域店铺佣金" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">城市店铺佣金</label>
									<div class="layui-input-inline">
										<input type="text" name="city_fee" placeholder="请输入城市店铺佣金" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>

							<!--<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">品牌名称</label>
									<div class="layui-input-inline">
										<input type="text" name="brand_name" placeholder="请输入品牌名称" autocomplete="off" class="layui-input">
									</div> 
									<div class="layui-form-mid layui-word-aux"><a href="Javascript:;" onclick="searchdata('brand_id')">选择</a></div>
								</div>
								<div class="layui-inline" style="display: none;">
									<label class="layui-form-label">品牌编号</label>
									<div class="layui-input-inline">
										<input type="text" name="brand_id" placeholder="请输入品牌编号" autocomplete="off" class="layui-input">
									</div>
								</div>
							</div> -->

							<fieldset class="layui-elem-field layui-form-item" style="width: 90%;margin-left: 50px;">
								<legend>规格</legend>
								<div class="layui-field-box" id="specView">
								  
								  <div class="layui-form-item">
									  <div class="layui-inline">
										  <label class="layui-form-label">规格名称</label>
										  <div class="layui-input-inline">
											  <input type="text" name="spec_k" placeholder="请输入规格名称" autocomplete="off" class="layui-input"  >
										  </div>
									  </div>
									  <div class="layui-inline">
										  <label class="layui-form-label">规格参数</label>
										  <div class="layui-input-inline">
											  <input type="text" name="spec_v" placeholder="请输入规格参数" autocomplete="off" class="layui-input" >
										  </div>
									  </div>
									  <button type="button" class="layui-btn layui-btn-sm spec_add"><i class="layui-icon"></i></button>
										 <button type="button" class="layui-btn layui-btn-sm spec_del" style="display: none;"><i class="layui-icon"></i></button>
								  </div>
								</div>
						  	</fieldset>

							<!--<div class="layui-inline">
											<label class="layui-form-label">价格</label>
											<div class="layui-input-inline">
												<input type="text" name="spec_price" placeholder="请输入价格" autocomplete="off" class="layui-input" >
											</div>
										</div>-->

							<div class="layui-form-item">
								
								
								<div class="layui-inline" style="display: none;">
									<label class="layui-form-label">点击量</label>
									<div class="layui-input-inline">
										<input type="text" name="hits" value="0" placeholder="请输入点击量" autocomplete="off"
											class="layui-input" lay-verify="hits">
									</div>
								</div>
								
								<!--<div class="layui-inline">
									<label class="layui-form-label">最低购买数量</label>
									<div class="layui-input-inline">
										<input type="text" name="low_quantity" placeholder="请输入最低购买数量" autocomplete="off" class="layui-input">
									</div>
								</div>-->
							</div>

							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">成本价<span style="color:red">*</span></label>
									<div class="layui-input-inline">
										<input type="text" name="cost_price" placeholder="请输入成本价" lay-verify="number"
											autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">原价<span style="color:red">*</span></label>
									<div class="layui-input-inline">
										<input type="text" name="price" placeholder="请输入购买原价" lay-verify="number"
											autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">购买会员价<span style="color:red">*</span></label>
									<div class="layui-input-inline">
										<input type="text" name="price_member" placeholder="请输入购买会员价"
											lay-verify="number" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<div class="layui-block">
										<label class="layui-form-label">折扣</label>
										<div class="layui-input-block">
											<input type="text" name="discount" placeholder="请输入折扣：0.99 代表99折"
												lay-verify="discount" autocomplete="off" class="layui-input">
										</div>
									</div>
								</div>
									
							</div>


							<!--<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">抢购价</label>
									<div class="layui-input-inline">
										<input type="text" name="limit_price" placeholder="请输入抢购价" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">营销价</label>
									<div class="layui-input-inline">
										<input type="text" name="market_price" placeholder="请输入营销价" autocomplete="off" class="layui-input">
									</div>
								</div> 
								<div class="layui-inline">
									<label class="layui-form-label">优惠价</label>
									<div class="layui-input-inline">
										<input type="text" name="coupon_price" placeholder="请输入优惠价" autocomplete="off" class="layui-input">
									</div>
								</div> 
							</div>-->
							<div class="layui-form-item" style="display: none;">
								<!--<div class="layui-inline">
									<label class="layui-form-label">积分百分比</label>
									<div class="layui-input-inline">
										<input type="text" name="score_scale"  placeholder="请输入积分抵扣百分比" autocomplete="off" class="layui-input">
									</div>
								</div>  -->
								<div class="layui-inline">
									<label class="layui-form-label">积分抵扣</label>
									<div class="layui-input-inline">
										<input type="text" name="score" lay-verify="number | required"
											placeholder="请输入积分抵扣" autocomplete="off" class="layui-input">

									</div>
								</div>
							</div>
							<div class="layui-form-item" style="display: none;">
								<div class="layui-inline">
									<label class="layui-form-label">专属等级</label>
									<div class="layui-input-inline">
										<select name="level" class="site_union">
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">赠送等级</label>
									<div class="layui-input-inline">
										<select name="grade" class="site_union">
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">赠送月份</label>
									<div class="layui-input-inline">
										<input type="text" name="grade_month" placeholder="请输入赠送月份" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>


							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">计量单位</label>
									<div class="layui-input-inline">
										<input type="text" name="measure_unit" placeholder="请输入计量单位" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">最低购买数量<span style="color:red">*</span></label>
									<div class="layui-input-inline">
										<input type="text" name="low_quantity" placeholder="请输入最低购买数量" autocomplete="off"
											class="layui-input" lay-verify="required">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">当前库存<span style="color:red">*</span></label>
									<div class="layui-input-inline">
										<input type="text" name="stock" placeholder="请输入当前库存" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline" style="display: none;">
									<label class="layui-form-label">当前销量<span style="color:red">*</span></label>
									<div class="layui-input-inline">
										<input type="text" name="sales" placeholder="请输入当前销量" autocomplete="off"
											class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">商品运费</label>
									<div class="layui-input-inline">
										<input type="text" name="price_waybill" placeholder="请输入商品运费" autocomplete="off"
											class="layui-input">
								
									</div>
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">发货说明</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入发货说明" name="instructions"
										class="layui-textarea"></textarea>
								</div>
							</div>


							<div class="layui-form-item">
								<label class="layui-form-label">商品简介</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入商品简介" name="intro" class="layui-textarea"></textarea>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">商品介绍</label>
								<div class="layui-input-block">
									<textarea class="layui-textarea layui-hide" name="content" lay-verify="content"
										id="demo_editor"></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">店铺信息</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入店铺信息" name="support" class="layui-textarea"></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">商品示例图</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(5)">上传图片</button>

									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="shili"></ul>
									</blockquote>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">商品主图</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(1)">上传图片</button>

									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="zhutu"></ul>
									</blockquote>
									<textarea placeholder="请输入售后保障" name="support" class="layui-textarea"></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">商品轮播图</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(2)">上传图片</button>

									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="lunbo"></ul>
									</blockquote>
								</div>
							</div>
							<div class="layui-form-item upvideo">
								<label class="layui-form-label">视频</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal upimgbtn"
										onclick="choose(3)">上传视频</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										预览视频：
										<div class="layui-upload-list upload_list" id="video_url">
											<ul class="show_img_ul" id="video"></ul>
										</div>
									</blockquote>

								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">商品视频封面</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(4)">上传图片</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="video_cover"></ul>
									</blockquote>
								</div>
							</div>
						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>


		<script type="text/html" id="sub_skuid">


		{{# layui.each(d,function(index,o){ }}

			<tr>
				<td>{{o.skuid}}</td>
				<td>{{o.skuname}}</td>
				<td>
					<button type="button" class="layui-btn layui-btn-danger del_tr" index="{{index}}"><i
							class="layui-icon"></i></button>
				</td>
			</tr>
			{{# })}}


		</script>

		<script type="text/html" id="specTpl">
			{{# layui.each(d, function(index, o){ }}
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">规格名称</label>
					<div class="layui-input-inline">
						<input type="text" name="spec_k" placeholder="请输入规格名称" autocomplete="off" class="layui-input" value="{{o.spec_k}}">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">规格参数</label>
					<div class="layui-input-inline">
						<input type="text" name="spec_v" placeholder="请输入规格参数" autocomplete="off" class="layui-input" value="{{o.spec_v}}">
					</div>
				</div>
				<button type="button" class="layui-btn layui-btn-sm spec_add"><i class="layui-icon"></i></button>
				{{#  if(index !== 0){ }}
				<button type="button" class="layui-btn layui-btn-sm spec_del"><i class="layui-icon"></i></button>
				{{#  } }} 
				{{#  if(index === 0){ }}
				<button type="button" class="layui-btn layui-btn-sm spec_del" style="display: none;"><i class="layui-icon"></i></button>
				{{#  } }}
			</div>
			{{# }) }}
		</script>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../js/ace/ace.js"></script>
		<script src="../../../js/common.js"></script>
		<!--<script src="https://raw.githack.com/hnzzmsf/layui-formSelects/master/dist/formSelects-v4.min.js" type="text/javascript" charset="utf-8"></script>-->
		<script src="../../../layuiadmin/modules/formSelects-v4.js"></script>
		<script>
			var _data = {
				skuid: getParam('skuid'),
				client: '200,201,202',
				spuid: ''
			}

			var urlParamData = {
				skuid: getParam('skuid'),
				cat_id: getParam('cat_id'),
				cat_name: getParam('cat_name')
			}

			var request_data = []
			var goods_arr = []
			var str = '';

			function child(data, index) {
				$(" input[name=spuname]").val(data.spuname);
				$(" input[name=spuid]").val(data.spuid);
			}

			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				tinymce: '../tinymce/tinymce',
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'tinymce', 'util'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					util = layui.util,
					tinymce = layui.tinymce,
					form = layui.form;

				on_off_show('radio');
				fq_status_show('radio');
				icon_type_show('checkbox')
				site_union_show("option")
				//goods_type_show('radio')
				var img_arr1 = [],
					img_arr2 = [],
					img_arr3 = [],
					img_arr4 = [];
				img_arr5 = [];
				//日期时间选择器
				laydate.render({
					elem: '#rangeStartTime',
					type: 'time'
				});
				laydate.render({
					elem: '#rangeEndTime',
					type: 'time'
				});

				var edit = tinymce.render({
					elem: "#demo_editor",
					height: 600
				});

				if (_data.skuid) {
					initdata();
				} else {
					// 新增商品
					if (urlParamData.cat_name) {
						$('input[name=categoryname]').val(urlParamData.cat_name)
						$('input[name=catid]').val(urlParamData.cat_id)
					}
					$('#choose_shopname').text(localStorage.getItem("pxy_shopname"))
					$('#sub_shopid').val(localStorage.getItem("pxy_shopid"))
					$('#sub_shopname').val(localStorage.getItem("pxy_shopname"))
				}
				init_service()

				function init_service() {

					var radio = $("input[name=type]")

					// class="service_goods"
					console.log(radio)

					for (var i = 0; i < radio.length; i++) {
						console.log(radio[i])
					}
					$.ajaxSettings.async = false;
					$.get(server.queryshopmodulelist, {
						page: 1,
						limit: 99,
						filterRules: [],
						sort: [],
						method: 'channel.index',
						fid: ''
					}, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.module_list.data;
								//data.shift()
								var rolehtml = "<option value=''>请选择</option>";
								for (var i = 0; i < data.length; i++) {
									rolehtml += '<option value=' + data[i].id + '>' + data[i].title + '</option>'
								}
								$(".site_icon_group").append(rolehtml);
								form.render('select')
								form.render('radio')

							}
							closeloading();
						} else {
							layer.msg('服务器连接错误');
						}
						$.ajaxSettings.async = true;
					});
				}
				form.on('radio(type)', function(data) {
					console.log(data.elem); //得到radio原始DOM对象
					var level = data.value; //被点击的radio的value值        

					console.log(level);
					console.log(level.toString() == '1');

					if (level.toString() == '1') {
						$(".service_goods").show();
					} else {
						$(".service_goods").hide();
					}


				})
				util.event('lay-event', {
					preveiw: function() {
						layer.open({
							type: 2,
							title: '预览',
							shadeClose: false,
							shade: 0.5,
							maxmin: true, //开启最大化最小化按钮
							area: ['60%', '80%'],
							content: 'pre_content.html',
							end: function() {},
							success: function(layero, index) {
								var body = layer.getChildFrame('body', index);
								body.find(".title").html($('input[name=title]').val());
								body.find(".showcontent").html(edit.getContent());
							}
						});
					},
				});

				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.goods_image_url = img_arr1.join(',');
					_data.goods_gallery_urls = img_arr2.join(',');
					_data.video_url = img_arr3.join(',');
					_data.video_cover = img_arr4.join(',');
					_data.examples_img_url = img_arr5.join(',');
					_data.content = edit.getContent();
					_data.client = '200,201,202';
					// for (item in data) {
					// 	if (/^c/.test(item)) {
					// 		if (item.substr(0, 6) == 'client') {
					// 			console.log(item.substr(0, 6))
					// 			_data.client += data[item] + ','
					// 		}
					// 	}
					// }
					// _data.client = (_data.client.substring(_data.client.length - 1) == ',') ? _data.client
					// 	.substring(0, _data.client.length - 1) : _data.client;
					_data.sub_skuid = ''
					for (var i = 0; i < goods_arr.length; i++) {
						_data.sub_skuid += goods_arr[i].skuid;
						if (i != goods_arr[i].length - 1) {
							_data.sub_skuid += ",";
						}
					}
					// 处理多规格参数
					var checkMsg = get_spec(_data)
					if (!checkMsg.flag) {
						layer.msg(checkMsg.msg)
						return false
					}
					// alert($("#catid").val());
					// alert(JSON.stringify(_data));
					// return false;
					// console.log(_data, '提交')
					var lock = false
					layer.confirm('确定要提交数据？', function() {
						if (!lock) {
							lock = true
							loading();
							if (_data.type == 0) {
								_data.test_typ == '';
							}
							if (_data.skuid) {
								if (_data)
								submitdata(server.updategoods);
								console.log(_data.examples_img_url);
							} else {
								_data.status = '-1' // 新增默认未审核
								submitdata(server.addgoods);
								// console.log(_data, '0000')
							}
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								closeloading();
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				// 选择子店铺
				window.chooseShop = function() {
					//alert();
					layer.open({
						type: 2,
						title: '选择店铺',
						shadeClose: false,
						shade: 0.5,
						maxmin: false, //开启最大化最小化按钮
						area: ['90%', '90%'],
						content: 'choose_shop_id.html',
						end: function() {

						},
						success: function(layer, index) {}
					});
				}
				window.selectShop = function(data) {
					if (data && data.length) {
						data = data[0];
						$('input[name=sub_shopid]').val(data.sub_shopid);
						$('input[name=sub_shopname]').val(data.sub_shopname);
						$('#choose_shopname').html(data.sub_shopname);
					}
				}


				window.searchdata = function(type) {
					switch (type) {
						case 'catid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['80%', '80%'],
								content: 'choose_cat.html',
								end: function() {},
								success: function() {}
							});
							break;
						case 'spuid':
							var cat_id = $('input[name=catid]').val()
							layer.open({
								type: 2,
								title: '选择产品',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['80%', '90%'],
								content: 'choose_spuid.html?cat_id=' + cat_id,
								end: function() {
									_data.spuid = $('input[name=spuid]').val()
									setTimeout(function() {
										productdetail(_data.spuid)
									}, 300)
								},
								success: function() {}
							});
							break;
						case 'brand_id':
							layer.open({
								type: 2,
								title: '选择品牌',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_brand.html',
								end: function() {
									_data.brand_id = $('input[name=brand_id]').val()


								},
								success: function() {}
							});
							break;
						case 'sub_skuid':
							layer.open({
								type: 2,
								title: '选择子商品',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_sub_goods.html',
								success: function() {

								},
								end: function() {
									console.log(_data)
									var skuid = _data.id ? _data.id.split(",") : ''
									var skunames = _data.skunames ? _data.skunames.split(",") : ''
									for (var i = 0; i < skuid.length; i++) {
										goods_arr.push({
											skuid: skuid[i],
											skuname: skunames[i]
										})
									}
									show_goods_arr(goods_arr)
								}
							});
							break;
						default:
							break;
					}
				}

				function show_goods_arr(goods_arr) {
					var getTpl = sub_skuid.innerHTML,
						view = document.getElementById('tbody_tr');
					laytpl(getTpl).render(goods_arr, function(html) {
						view.innerHTML = html;
					});
				}
				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: 'up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}
				window.getimg = function(data, type) {
					console.log(data);
					if (data) {
						switch (type) {
							case '1':
								createli(data, 'zhutu', type)
								break;
							case '2':
								createli(data, 'lunbo', type)
								break;
							case '3':
								createli(data, 'video_url', type)
								break;
							case '4':
								createli(data, 'video_cover', type)
								break;
							case '5':
								createli(data, 'shili', type)
								break;
							default:
								break;
						}
					}
				}
				window.delimg = function(i, type, _self) {
					var _type = String(type)
					var lock = false
					layer.confirm('确定要删除图片？', function(index) {
						if (!lock) {
							lock = true
							switch (_type) {
								case '1':
									img_arr1.splice(i, 1)
									break;
								case '2':
									img_arr2.splice(i, 1)
									break;
								case '3':
									img_arr3.splice(i, 1)
									break;
								case '4':
									img_arr4.splice(i, 1)
									break;
								case '5':
									img_arr5.splice(i, 1)
									break;
								default:
									break;
							}
							$(_self).parent().remove();
							layer.close(index)
						}
					}, function() {
						layer.msg('取消操作');
					});
					// console.log(i);
					// console.log(type);

				}

				function createli(data, dom, type) {
					// console.log(data);
					var lihtml = '';
					switch (type) {
						case '1':
							if (data.indexOf(',') == -1) {
								img_arr1.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr1.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr1.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr1[i] + ' >' +
									'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
									'</li>'
							}
							break;
						case '2':
							if (data.indexOf(',') == -1) {
								img_arr2.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr2.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr2.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr2[i] + ' >' +
									'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
									'</li>'
							}
							break;
						case '3':
							if (data.indexOf(',') == -1) {
								img_arr3.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr3.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr3.length; i++) {
								//								lihtml += '<li class="show_img_li">' +
								//									'<img src=' + img_arr3[i] + ' >' +
								//									'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
								//									'</li>'
								lihtml += '<li class="show_img_li">' +
									'<video controls="controls" id="video{{index}}" width="320" height="240"><source src=' +
									img_arr3[i] + ' type="video/ogg" /><source src=' + img_arr3[i] +
									' video/mp4" /></video>' +
									'<p onclick="delimg(' + i + ',3,this)">删除</p>' +
									'</li>'
							}

							break;
						case '4':
							if (data.indexOf(',') == -1) {
								img_arr4.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr4.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr4.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr4[i] + ' >' +
									'<p onclick="delimg(' + i + ',4,this)">删除</p>' +
									'</li>'
							}
							break;
						case '5':
							if (data.indexOf(',') == -1) {
								img_arr5.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr5.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr5.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr5[i] + ' >' +
									'<p onclick="delimg(' + i + ',5,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}

				function initdata() {
					loading()
					$.get(server.querygoodsdetail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.goods_info

								$('#choose_shopname').text(data.data.sub_shopname)
								$("input[name=status]").val(data.data.status);
								$("input[name=type][value=" + data.data.type + "]").attr("checked", true);
								$("input[name=level][value=" + data.data.level + "]").attr("checked", true);


								data.data.goods_image_url ? createli(data.data.goods_image_url, 'zhutu', '1') :
									''
								data.data.goods_gallery_urls ? createli(data.data.goods_gallery_urls, 'lunbo',
									'2') : ''

								data.data.video_url ? createli(data.data.video_url, 'video_url', '3') : ''
								data.data.video_cover ? createli(data.data.video_cover, 'video_cover', '4') : ''
								data.data.examples_img_url ? createli(data.data.examples_img_url, 'shili', '5') :
									''


								console.log(data.data.spec)

								_data.spuid = data.data.spuid;

								$(".on_off input[value=" + data.data.status + "]").attr("checked", true)

								if (data.data.client) {
									var client_arr = data.data.client.split(',')
									for (var i = 0; i < client_arr.length; i++) {
										$(".icon_type input[value=" + client_arr[i] + "]").attr("checked", true)
									}
								}

								if (data.data.sub_service) {
									for (var i = 0; i < data.data.sub_service.length; i++) {
										goods_arr.push({
											skuid: data.data.sub_service[i].skuid,
											skuname: data.data.sub_service[i].skuname
										})
									}
									show_goods_arr(goods_arr)
									console.log(goods_arr)
								}
								if (data.data.type.toString() == '1') {
									$(".service_goods").show();
								} else {
									$(".service_goods").hide();
								}
								if (data.data.channelid) {

									$("#channelid option[value='" + data.data.channelid + "']").prop("selected",
										"selected");
								}
								// 解析规格并展示
								showSpec(data.data)
								form.val("test_detail", data.data);
								form.render();
								edit.setContent(data.data.content)
								// layedit.setContent(indexbuild,data.data.content);

								closeloading()
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
					closeloading()
				}
				/**
				 * 
				 * @param {Object} type 0 add , 1  edit
				 * @param {Object} edit
				 */
				window.productdetail = function(spuid, type) {
					if (!spuid) {
						return
					}
					loading()
					$.get(server.op_queryproductdetail, {
						spuid: spuid
					}, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.product
								//*******************************//
								data.data.goods_img ? createli(data.data.goods_img, 'zhutu', '1') : ''
								data.data.gallery_url ? createli(data.data.gallery_url, 'lunbo', '2') : ''
								data.data.video_url ? createli(data.data.video_url, 'video_url', '3') : ''
								data.data.video_cover ? createli(data.data.video_cover, 'video_cover', '4') :
									''
								data.data.examples_img_url ? createli(data.data.examples_img_url, 'shili',
									'5') : ''
								data.data.spuname ? $("input[name=skuname]").val(data.data.spuname) : ""
								data.data.specname ? $("input[name=specname]").val(data.data.specname) : ""
								data.data.specparam ? $("input[name=specparam]").val(data.data.specparam) :
									""
								data.data.price ? $("input[name=price]").val(data.data.price) : ""
								data.data.score_scale ? $("input[name=score_scale]").val(data.data
									.score_scale) : ""


								data.data.brandid ? $("input[name=brand_id]").val(data.data.brandid) : ""
								data.data.brandname ? $("input[name=brand_name]").val(data.data.brandname) :
									""

								data.data.intro ? $("textarea[name=intro]").val(data.data.intro) : ""
								data.data.support ? $("textarea[name=support]").val(data.data.support) : ""
								data.data.instructions ? $("textarea[name=instructions]").val(data.data
									.instructions) : ""


								data.data.price_member ? $("input[name=price_member]").val(data.data
									.price_member) : ""
								data.data.price_waybill ? $("input[name=price_waybill]").val(data.data
									.price_waybill) : ""
								data.data.notes ? $("input[name=notes]").val(data.data.notes) : ""



								//querygoodsdata1(data.data.catid, 'catid')

								edit.setContent(data.data.content)

							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
					closeloading()

				}


				$(document).on("click", ".spec_add", function(e) {
					var $current = $(this)
					var cloneNode = $current.parent().clone(true) //当前父节点
					cloneNode.find(".spec_del").css("display", "inline-block")
					cloneNode.find('input[name=spec_k]').val('')
					cloneNode.find('input[name=spec_v]').val('')
					$current.parent().parent().append(cloneNode)
				})

				$(document).on("click", '.spec_del', function(e) {
					var $current = $(this)
					$current.parent().remove()
				})

				function get_spec(_data) {
					var specname = [], specparam = [], checkMsg = {flag: true, msg: ''}
					$('input[name=spec_k]').each(function() {
						var spec_k = $(this).val()
						var spec_v = $(this).parent().parent().parent().find('input[name=spec_v]').val()
						console.log(spec_k + '||' + spec_v)
						if (spec_k != '' && spec_v != '') {
							if (specname.indexOf(spec_k) >= 0) {
								checkMsg.flag = false
								checkMsg.msg += '规格：[' + spec_k + ']重复</br>';
							} else {
								specname.push(spec_k)
								specparam.push(spec_v)
							}
						}
					})
					_data['specname'] = specname.join(',')
					_data['specparam'] = specparam.join(',')
					return checkMsg
				}

				function showSpec(_data) {
					if (!_data.specname) {
						return
					}
					var specname = _data.specname.split(',')
					var specparam = _data.specparam.split(',')
					var showSpecData = []
					$.each(specname, function(index, item) {
						showSpecData.push({
							spec_k: item,
							spec_v: specparam[index]
						})
					})
					var view = document.getElementById('specView')
					laytpl(specTpl.innerHTML).render(showSpecData, function(html) {
						view.innerHTML = html;
						setTimeout(function() {
							$(".spec_del").bind("click")
						}, 500)
					});
				}
				//				$("input[name=score]").bind("blur",function(e){
				//					var price_member = $("input[name=price_member]").val()
				//					var score = $("input[name=score]").val()
				//					if (score>0  && price_member>0) {
				//						var sumprice_member = Math.round(parseFloat(price_member) * 100) / 100
				//						var sumScore = Math.round(parseFloat(score) * 100) / 100 
				//						var sumScale = Math.round(parseFloat((sumScore/sumprice_member).toFixed(2)) * 100)  
				//						var scale = $("input[name=score_scale]").val(sumScale)
				//					}
				//				})
				//				$("input[name=score_scale]").bind("blur",function(e){
				//					var price_member = $("input[name=price_member]").val()
				//					var score_scale = $("input[name=score_scale]").val()
				//					if (score_scale || price_member) {
				//						var sumScore = Math.round(parseFloat((price_member*score_scale).toFixed(2)) * 100) /10000
				//						var scale = $("input[name=score]").val(sumScore)
				//					}
				//				})
				//				
				$(document).on("click", ".del_tr", function(e) {

					var index = $(this).attr("index")
					goods_arr.splice(index - 1, 1)
					console.log(goods_arr)
					$(this).parent().parent().remove()
					$(this).parent().parent().remove()
				})

			});
		</script>
	</body>
</html>
